﻿using System.Collections.Generic;
using System.Linq;
using Library.OrmEnterpriseEntity.TableInfo;

namespace Library.OrmEnterpriseEntity {
	/// <summary>
	/// The class for excuted some commons action to DBMS
	/// </summary>

	public static class QueryRun {
		/// <summary>
		/// Perform select statement
		/// </summary>
		/// <param name="columns"></param>
		/// <returns></returns>
		public static SelectStatement Select(params DbColumnView[] columns) {
			return new SelectStatement(columns);
		}
		/// <summary>
		/// Perform select statement
		/// </summary>
		/// <param name="columns"></param>
		/// <param name="more"></param>
		/// <returns></returns>
		public static SelectStatement Select(ColumnViewCollection columns, params DbColumnView[] more) {
			var list = columns.ToList();
			list.AddRange(more);
			return new SelectStatement(list.ToArray());
		}
		/// <summary>
		/// Perform select statement
		/// </summary>
		/// <param name="columns"></param>
		/// <returns></returns>
		public static SelectStatement Select(params ColumnViewCollection[] columns) {
			var list = new List<DbColumnView>();
			foreach (var columnCollection in columns) {
				list.AddRange(columnCollection);
			}
			return new SelectStatement(list.ToArray());
		}
		/// <summary>
		/// Perform delete statement
		/// </summary>
		/// <param name="table"></param>
		/// <returns></returns>
		public static DeleteQueryStatement Delete(GlobalEntityView table) {
			return new DeleteQueryStatement(table);
		}
		/// <summary>
		/// Perform update statement
		/// </summary>
		/// <param name="table"></param>
		/// <returns></returns>
		public static UpdateQueryStatement Update(GlobalEntityView table) {
			return new UpdateQueryStatement(table);
		}

		/// <summary>
		/// Perform SQL statement
		/// </summary>
		/// <param name="commandText">command text</param>
		/// <returns>SqlStatement</returns>
		public static SqlStatement Sql(string commandText) {
			return new SqlStatement(commandText);
		}
		/// <summary>
		/// Perform SQL statement
		/// </summary>
		/// <param name="commandText">command type</param>
		/// <param name="parameter">parameter</param>
		/// <returns>SqlStatement</returns>
		public static SqlStatement Sql(string commandText, QueryParameter parameter) {
			return new SqlStatement(commandText, parameter);
		}
	}
}
